﻿using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using System.Windows.Forms;

namespace Swsk33.SimpleArcEngine.Dialog
{
	public partial class SelectQueryDialog : Form
	{
		/// <summary>
		/// 传入地图控件
		/// </summary>
		private AxMapControl mapControl;

		public SelectQueryDialog(AxMapControl map)
		{
			InitializeComponent();
			mapControl = map;
		}

		/// <summary>
		/// 双击闪烁指定图层
		/// </summary>
		private void resultList_DoubleClick(object sender, System.EventArgs e)
		{
			// 遍历每一个图层以找到列表中选择的图层
			for (int i = 0; i < mapControl.LayerCount; i++)
			{
				IFeatureLayer layer = (IFeatureLayer)mapControl.get_Layer(i);
				// ListView中被分为了几列，那么一个Item（一行）即为全部列的集合，这里第一个为图层名
				ListViewItem item = resultList.SelectedItems[0];
				// 如果当前选择的列表项的名字和图层名字一致，则开始在当前图层查询
				if (layer.Name == item.Text)
				{
					IQueryFilter filter = new QueryFilter();
					filter.SubFields = "*";
					// 查询OID为当前选中的OID的要素，当前一行中第二列为OID
					filter.WhereClause = layer.FeatureClass.OIDFieldName + "=" + item.SubItems[1].Text;
					IFeatureCursor cursor = layer.Search(filter, false);
					IFeature feature = null;
					while ((feature = cursor.NextFeature()) != null)
					{
						mapControl.FlashShape(feature.Shape);
					}
				}
			}
		}
	}
}